<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\facade\Route;
use think\Response;
use think\swoole\response\File;

Route::get('admin/:path', function (string $path) {
    $filename = public_path('admin') . $path;
    return new File($filename);
})->pattern(['path' => '.*\.\w+$']);

Route::get('admin/', function () {
    $viewPath = public_path() . 'admin/index.html';
    if (!file_exists($viewPath)) {
        throw new Exception('官方后台视图模板文件不存在');
    }
    $content = file_get_contents($viewPath);
    $response = Response::create()->content($content);
    return $response;
});
Route::redirect('admin', 'admin/', 302);

Route::get('assets/:path', function (string $path) {
    $filename = public_path('assets') . $path;
    return new File($filename);
})->pattern(['path' => '.*\.\w+$']);


Route::get('static/:path', function (string $path) {
    $filename = public_path('static') . $path;
    return new File($filename);
})->pattern(['path' => '.*\.\w+$']);
